<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['diy']=$this->plugin_setting('diy');
$basic=$return['pluginset'];
$return['basic']=$basic;
$return['banner']=$basic['hdps'];
$return['setting']=array(
	'bankuai1'=>$basic['bankuai']
);
if($_RQ['op']=='main'){
	exi('','','jy_xiuvote/r_detail/');
	if($_RQ['isdownsao']){
		$this->session('isdownsao',$_RQ['isdownsao']);
	}
	/*******main*******/
	//首页轮播图
	//首页推荐项目
	$return['groups']=pdo_getall('jy_xiuvote_groups',array('uniacid'=>$_SESSION['uniacid'],'isshow'=>1),'','id desc');
	
	//公告列表
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$notice_list = pdo_getslice('jy_weishop_notice',array('uniacid'=>$_SESSION['uniacid'],'status'=>1),array($pindex,20),$total,array('id','title','createtime'),'','id desc');
	if($notice_list){
		foreach($notice_list as &$notice){
			if($_SESSION['os']=='windows'){
				$notice['createtime']=date('m-d',$notice['createtime']);
			}else{
				$notice['createtime']=date('Y-m-d h:i',$notice['createtime']);
			}
		}
	}
	$return['notices']=$notice_list;
	set_html('title',$basic['title']?'首页-'.$basic['title']:'首页');
	$return['sharedata']=array(
		'title'=>$basic['share_title'],
		'desc'=>$basic['share_desc'],
		'link'=>custom_url('jy_xiuvote/index/',true),
		'imgUrl'=>ATTACHMENT_URL.$basic['share_image'],
	);
	$return['params']=array('page'=>1,'keyword'=>'');
	if($_RQ['keyword']){
		$return['params']['keyword']=$_RQ['keyword'];
	}
	//是否关注
	$return['isfollow']=pdo_getcolumn('core_fans',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'follow');
	$return['msg'] = pdo_count('jy_xiuvote_notice_log', array('uid'=>$uid,'isread'=>0,'type'=>$type),'id');
	exi($return);
}
if($_RQ['op']=='getreply'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>'1');
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$list=pdo_getslice('jy_xiuvote_reply',$params,array($pindex,$psize),$total,$fields,'','paixu desc, id desc');
	if($list){
		foreach($list as &$r){
			if($r['starttime']>time()){
				$r['statustitle']='未开始';
			}
			if($r['endtime']>time() && $r['starttime']<time()){
				$r['statustitle']='进行中';
			}
			if($r['endtime']<time()){
				$r['statustitle']='已结束';
			}
			$r['onum']=pdo_count('jy_xiuvote_opus',array('uniacid'=>$_SESSION['uniacid'],'rid'=>$r['id'],'status'=>1,'isshow'=>1));
			$r['starttime']=date('Y-m-d h:m:s',$r['starttime']);
		}
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='getlist'){
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'isshow'=>1);
	if($_RQ['rid']){
		$params['rid']=intval($_RQ['rid']);	
		$reply=pdo_get('jy_xiuvote_reply',array('id'=>$_RQ['rid'],'uniacid'=>$_SESSION['uniacid']),array('groupid'));
		$ridtype=pdo_getcolumn('jy_xiuvote_groups',array('uniacid'=>$_SESSION['uniacid'],'id'=>$reply['groupid']),'type');
	}
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);	
	}
	if($_RQ['keyword']){
		if(is_numeric($_RQ['keyword'])){
			$params['id']=intval($_RQ['keyword']);
		}else{
			$params['realname like']='%'.$_RQ['keyword'].'%';
		}
		$return['params']['keyword']=$_RQ['keyword'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$list=pdo_getslice('jy_xiuvote_opus',$params,array($pindex,$psize),$total,$fields,'','likes desc');
	foreach($list as &$kv){
			$reply=pdo_get('jy_xiuvote_reply',array('id'=>$kv['rid'],'uniacid'=>$_SESSION['uniacid']),array('groupid'));
			$grouptype=pdo_getcolumn('jy_xiuvote_groups',array('uniacid'=>$_SESSION['uniacid'],'id'=>$reply['groupid']),'type');
			$jifen=pdo_getsum('jy_xiuvote_sendlplog',array('oid'=>$kv['id'],'uniacid'=>$_SESSION['uniacid'],'status'=>1),'jifen');
			$kv['votenums']=pdo_count('jy_xiuvote_votelog',array('oid'=>$kv['id'],'uniacid'=>$_SESSION['uniacid'],'is_shenhe'=>1));
			$kv['votenums1']=pdo_count('jy_xiuvote_votelog',array('isline'=>1,'oid'=>$kv['id'],'uniacid'=>$_SESSION['uniacid'],'is_shenhe'=>1));
			$kv['votenums2']=pdo_count('jy_xiuvote_votelog',array('isline'=>0,'oid'=>$kv['id'],'uniacid'=>$_SESSION['uniacid'],'is_shenhe'=>1));
			if($grouptype!=1){
				$kv['votenums']=$kv['basevotenums']+$kv['votenums']+$jifen;
				$kv['votenums1']=$kv['basevotenums']+$kv['votenums1']+$jifen;
			}else{
				$kv['likes']=$kv['baselikenums']+$kv['likes']+$jifen;
			}
			$kv['thumb']=tomedia($kv['thumb']);
	}
	//按点赞数排序作品
	$return['likes']=pdo_getsum('jy_xiuvote_opus',array('status'=>1),'likes');
	$return['look']=pdo_getsum('jy_xiuvote_opus',array('status'=>1),'look');
	if($list){
		$sum=count($list);
		foreach($list as &$item){
			$votenums=$item['votenums'];
			$votenums1=$item['votenums1'];
			$votenums2=$item['votenums2'];
			$likes=$item['likes'];
			$item=pdo_get('jy_xiuvote_opus',array('id'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
			$reply=pdo_get('jy_xiuvote_reply',array('id'=>$item['rid'],'uniacid'=>$_SESSION['uniacid']));
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['reply']=$reply;
			$item['opus_images']=json_decode($item['opus_images'],true);
			$item['picsnum']=count($item['opus_images']);
			$item['group']=pdo_get('jy_xiuvote_groups',array('uniacid'=>$_SESSION['uniacid'],'id'=>$reply['groupid']));
			$item['votenums']=$votenums;
			$item['votenums1']=$votenums1;
			$item['votenums2']=$votenums2;
			$item['likes']=$likes;
			$member=pdo_get('core_members',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),array('nickname','avatar'));
			$item['realname']=$item['realname']?$item['realname']:'';
			$item['avatar']=$item['avatar']?$item['avatar']:$member['avatar'];
			$item['thumb']=tomedia($item['thumb']);
		}
	}
	$return['list']=$list;
	$return['params']['page'] =$pindex;
	$return['reply']=$reply;
	$return['intDiff']=$reply['endtime']- time();
	$return['endstatus']= $reply['endtime'] < time()? 2 : $reply['starttime'] <time()?1:0;
	$return['apstatus']= $reply['apendtime'] < time()? 2 : $reply['apstarttime'] <time()?1:0;
	exi($return);
}